import api from '../../../../utils/api'
import {
  throttle2
} from '../../../../utils/util';


Component({
  options: {
    addGlobalClass: true,
    pureDataPattern: /^_/, // 指定所有 _ 开头的数据字段为纯数据字段
  },
  /**
   * 组件的属性列表
   */
  properties: {
    resource: {
      type: Object,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    getList(option) {
      api.orderDetail({
        data: {
          source: option.source,
          orderNo: option.order_no
        },
        success: res => {
          if (res.code * 1 === 0) {
            switch (res.data.vaccineOrder.status) {
              case -1:
                this.jumpSuccess(option)
                break;
              case 1:
                this.jumpRegister(option)
                break;
              case 2:
                this.jumpSuccess(option)
                break;
              case 3:
                this.jumpSuccess(option)
                break;
              case 4:
                this.jumpSuccess(option)
                break;
              default:
                this.jumpRegister(option)
                break;
            }
          }
        }
      })
    },
    jumpSuccess(resource) {
      wx.navigateTo({
        url: `/pages/registered-success/index?source=${resource.source}&orderNo=${resource.order_no}`
      })
    },
    jumpRegister(resource) {
      wx.navigateTo({
        url: `../registeredVaccine/registeredVaccine?source=${resource.source}&orderNo=${resource.order_no}&healthExam=${resource.healthExam}`
      })
    },
    onJumpBythrottle2: throttle2(function () {
      const resource = this.data.resource;
      console.log('resource: ', resource);
      if (resource.source) {
        this.getList(resource)
      } else {
        wx.showToast({
          title: '请到 我的->我的预约->待登记 里登记接种人信息',
          icon: 'none',
          duration: 1500,
        });
      }
    }, 2000),
    onjump() {
      this.onJumpBythrottle2()
    }
  }
})